;(function($){
	//by cfxixi 20121107
    var oldInterval;
    //将Date型format成("yyyy年MM月dd日hh小时mm分ss秒");
    Date.prototype.format = function(format){
        /*
         * eg:format="YYYY-MM-dd hh:mm:ss";
         使用方法:
         var testDate = new Date();
         var testStr = testDate.format("yyyy年MM月dd日hh小时mm分ss秒");
         alert(testStr);
         */
        var o = {
            "M+" :  this.getMonth()+1,  //month
            "d+" :  this.getDate(),     //day
            "h+" :  this.getHours(),    //hour
            "m+" :  this.getMinutes(),  //minute
            "s+" :  this.getSeconds(), //second
            "q+" :  Math.floor((this.getMonth()+3)/3),  //quarter
            "S"  :  this.getMilliseconds() //millisecond
        }

        if(/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
        }

        for(var k in o) {
            if(new RegExp("("+ k +")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
            }
        }
        return format;
    }



	var vendor = (/webkit/i).test(navigator.appVersion) ? 'webkit' :
		(/firefox/i).test(navigator.userAgent) ? 'Moz' :
		(/trident/i).test(navigator.userAgent) ? 'ms' :
		'opera' in window ? 'O' : '',

		// Browser capabilities
	    isAndroid 		= 	(/android/gi).test(navigator.appVersion),
	    isAndroid2		= 	(/android\s(1|2|3)\./gi).test(navigator.appVersion),
	    isIOS			= 	(/iphone|ipad/gi).test(navigator.appVersion),
	    isPlaybook		= 	(/playbook/gi).test(navigator.appVersion),
	    isTouchPad		= 	(/hp-tablet/gi).test(navigator.appVersion),
	    isWindows		= 	(/Windows/gi).test(navigator.appVersion),
	    isPC			= 	!isAndroid && !isIOS && !isPlaybook && !isTouchPad,
	    isIphone5		= 	(window.screen.height == 568 && isIOS)
	    hasTouch		= 	'ontouchstart' in window && !isTouchPad,

	    cancelFrame = (function () {
		    return window.cancelRequestAnimationFrame
				|| window.webkitCancelAnimationFrame
				|| window.webkitCancelRequestAnimationFrame
				|| window.mozCancelRequestAnimationFrame
				|| window.oCancelRequestAnimationFrame
				|| window.msCancelRequestAnimationFrame
				|| clearTimeout;
		})(),

		easing = {
			easeOutCirc: function (t, b, c, d) {
		        return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
		    },
		    liner: function(t,d) {
		    	return t / d;
		    }
		};



	// 为touchStart和touchEnd添加和删除hover效果
	// 并做延时处理，防止用户在拖拽的时候会也响应hover效果
	// 也就是说，用户只有在按住不动的100毫秒后响应，期间手指有移动则100毫秒后不响应
	var touchHover = {
		start: function(e){
			var _this = $(this);
			var _t = setTimeout(function(){
				_this.attr("hover", "on");
			}, 10);
			_this.attr("hoverTimeout", _t);
		},
		move: function(e) {
			var _this = $(this);
			clearTimeout( _this.attr("hoverTimeout") );
			_this.removeAttr("hoverTimeout");
			_this.removeAttr("hover");
		},
		end: function(e){
			var _this = $(this);
			clearTimeout( _this.attr("hoverTimeout") );
			var _t = setTimeout(function(){
				_this.removeAttr("hover");
			}, 100);
			_this.attr("hoverTimeout", _t);
		}
	};



	// 当touchstart之后手指有移动后，$.touchMoved为false，如果没有移动，为true
	var touchmove = {
		init: function() {
			$(document).on("touchstart", this.moved);
			$(document).on("touchmove", this.moved);
		},
		moved: function(e)  {
			if (e.type == "touchstart") {
				$.touchMoved = false;
			} else if (e.type == "touchmove") {
				$.touchMoved = true;
			}
		}
	}

	touchmove.init();

	

	// 页面转场动画中的一些参数
	var pageToVars = {
		current: null,
		target: null,
		type: null,
		callback: null,
		hover: null,
		ab: 1,
		back: null,
		afinish: false,
		bfinish: false,
		timeout: 0,
		runTime: 0.4,
		ease: "ease-out",
		// 根据pid属性判断两个页面的关系
		// 1表示目标页为后页, -1表示目标页为前页, 0表示两页不在同一层级
		catchId: function(a, b){
			if (a && b) {
				var _a = a.split('/'), _b = b.split('/');
				if(_a.length != _b.length) {
					if (a.indexOf(b) != -1) {
						return -1;
					} else if (b.indexOf(a) != -1) {
						return 1
					} else {
						return 0;
					}
				}else{
					if (_a.length > 2 && _a.slice(0, _a.length - 1) != _b.slice(0, _b.length - 1)) {
						return 0;
					} else if (_b[_b.length - 1] - _a[_a.length - 1] > 0) {
						return 1;
					} else {
						return -1;
					}
				}
			}
		},
		start: function() {
			// 如果正在转场，不执行动画
			if ($.pageToing) {
				return false;
			}
			$.pageToing = true;

			// 如果转场动画为none或者设备为android2.x|3.x
			if (this.type == "none" || isAndroid2) {
				this.end();
				return false;
			}
			
			// 如果有高亮，添加
			if (this.hover) {
			    clearTimeout( this.hover.attr("hoverTimeout") );
                this.hover.removeAttr("hoverTimeout");
			    this.hover.attr("hover", "on");
			}

			// 如果没有设置过back参数，判断两页面的关系
			if (this.back == undefined) {
				this.ab = this.catchId( this.current.attr("pid") , this.target.attr("pid") );
			} else {
				this.ab = this.back ? -1 : 1;
			}

			// 初始化动画完成的布尔
			this.afinish = false;
			this.bfinish = false;

			// 开始做转场动画
			this.current.css({"display": "block", "zIndex": "98", "opacity": "1", "pointerEvents": "none"}).on("webkitAnimationEnd", pageToVars.onevt);
			this.target.css({"display": "block", "zIndex": "99", "opacity": "1", "pointerEvents": "none"}).on("webkitAnimationEnd", pageToVars.onevt);

			// 头部添加动画样式表
			if ($("#_nadoFrames_") != null) {
				$("#_nadoFrames_").remove();
			}
			var _styleCss = "<style id='_nadoFrames_'>";
			switch (pageToVars.type) {
				case "move":
					pageToVars.runTime = 0.3;
					pageToVars.ease = "ease-out";
					if (pageToVars.ab != -1) {
						_styleCss += "@-webkit-keyframes pageAnimateRunCurrent { from {-webkit-transform: translate3d(0px, 0px, 0px);} to {-webkit-transform: translate3d(-100%, 0px, 0px);} }";
						_styleCss += "@-webkit-keyframes pageAnimateRunTarget { from {-webkit-transform: translate3d(100%, 0px, 0px);} to {-webkit-transform: translate3d(0px, 0px, 0px);} }";
					} else {
						_styleCss += "@-webkit-keyframes pageAnimateRunCurrent { from {-webkit-transform: translate3d(0px, 0px, 0px);} to {-webkit-transform: translate3d(100%, 0px, 0px);} }";
						_styleCss += "@-webkit-keyframes pageAnimateRunTarget { from {-webkit-transform: translate3d(-100%, 0px, 0px);} to {-webkit-transform: translate3d(0px, 0px, 0px);} }";
					}
					break;
				case "fb":
					pageToVars.runTime = 0.4;
					pageToVars.ease = "ease-out";
					_styleCss += "@-webkit-keyframes pageAnimateRunCurrent { from {-webkit-transform: scale3d(1,1,1); opacity: 1;} to {-webkit-transform: scale3d(0.9,0.9,1); opacity: 0;} }";
					if (pageToVars.ab != -1) {
						_styleCss += "@-webkit-keyframes pageAnimateRunTarget { 0% {-webkit-transform: translate3d(100%, 0px, 0px)} 20% {-webkit-transform: translate3d(100%, 0px, 0px)} 100% {-webkit-transform: translate3d(0, 0px, 0px)} }";
					} else {
						_styleCss += "@-webkit-keyframes pageAnimateRunTarget { 0% {-webkit-transform: translate3d(-100%, 0px, 0px)} 20% {-webkit-transform: translate3d(-100%, 0px, 0px)} 100% {-webkit-transform: translate3d(0, 0px, 0px)} }";
					}
					break;
				case "cover":
					pageToVars.runTime = 0.3;
					pageToVars.ease = "ease-out";
					_styleCss += "@-webkit-keyframes pageAnimateRunCurrent { from {-webkit-transform: translate3d(0px, 0px, 0px);} to {-webkit-transform: translate3d(0px, 0px, 0px);} }";
					if (pageToVars.ab != -1) {
						_styleCss += "@-webkit-keyframes pageAnimateRunTarget { from {-webkit-transform: translate3d(100%, 0px, 0px)} to {-webkit-transform: translate3d(0px, 0px, 0px)} }";
					} else {
						_styleCss += "@-webkit-keyframes pageAnimateRunTarget { from {-webkit-transform: translate3d(-100%, 0px, 0px)} to {-webkit-transform: translate3d(0px, 0px, 0px)} }";
					}
					break;
				case "fade":
					pageToVars.runTime = 0.3;
					pageToVars.ease = "ease-out";
					_styleCss += "@-webkit-keyframes pageAnimateRunCurrent { from {opacity: 1;} to {opacity: 0;} }";
					_styleCss += "@-webkit-keyframes pageAnimateRunTarget { from {opacity: 0;} to {opacity: 1;} }";
					break;
				case "scale":
					pageToVars.runTime = 0.25;
					pageToVars.ease = "ease-out";
					_styleCss += "@-webkit-keyframes pageAnimateRunCurrent { from {-webkit-transform: scale3d(1,1,1); opacity: 1;} to {-webkit-transform: scale3d(0.3,0.3,1); opacity: 0;} }";
					_styleCss += "@-webkit-keyframes pageAnimateRunTarget { from {-webkit-transform: scale3d(0.3,0.3,1); opacity: 0;} to {-webkit-transform: scale3d(1,1,1); opacity: 1;} }";
					break;
				case "poker":
					pageToVars.runTime = 0.25;
					pageToVars.ease = "linear";
					pageToVars.current.parent().style("-" + vendor + "-perspective", "2000px");

					if (pageToVars.ab != -1) {
						_styleCss += "@-webkit-keyframes pageAnimateRunCurrent { from {-webkit-transform: rotateY(0deg) scale3d(1,1,1); opacity: 1;} to {-webkit-transform: rotateY(-90deg) scale3d(0.9,0.9,1); opacity: 0.7;} }";
						_styleCss += "@-webkit-keyframes pageAnimateRunTarget { from {-webkit-transform: rotateY(90deg) scale3d(0.9,0.9,1); opacity: 0.7;} to {-webkit-transform: rotateY(0deg) scale3d(1,1,1); opacity: 1;} }";
					} else {
						_styleCss += "@-webkit-keyframes pageAnimateRunCurrent { from {-webkit-transform: rotateY(0deg) scale3d(1,1,1); opacity: 1;} to {-webkit-transform: rotateY(90deg) scale3d(0.9,0.9,1); opacity: 0.7;} }";
						_styleCss += "@-webkit-keyframes pageAnimateRunTarget { from {-webkit-transform: rotateY(-90deg) scale3d(0.9,0.9,1); opacity: 0.7;} to {-webkit-transform: rotateY(0deg) scale3d(1,1,1); opacity: 1;} }";
					}
					break;
			}
			_styleCss += "</style>";
			$("head").append(_styleCss);

			// 添加animation样式，动画形式为scale或poker时，target暂时不添加，并隐藏
			this.current.css("-" + vendor + "-animation", "pageAnimateRunCurrent " + pageToVars.runTime + "s " + pageToVars.ease);
			if (this.type !== "scale" && this.type !== "poker") {
				this.target.css("-" + vendor + "-animation", "pageAnimateRunTarget " + pageToVars.runTime + "s " + pageToVars.ease);
			} else {
				this.target.hide();
			}

			// 动画安全锁，2秒后动画未结束，自动结束
			clearTimeout(this.timeout);
			this.timeout = setTimeout(function(){
				if ($.pageToing) {
					pageToVars.current.off("webkitAnimationEnd", pageToVars.onevt);
					pageToVars.target.off("webkitAnimationEnd", pageToVars.onevt);
					pageToVars.end();
				}
			},2000);
		},
		onevt: function(e) {
			if (e.type === "webkitAnimationEnd") {
				// 如果事件对象是current，说明current的动画已经完成
				// current隐藏，删除侦听，并删除动画时添加的样式
				// 如果转场动画为scale或poker，执行下半部分动画
				if (e.target == pageToVars.current[0]) {
					pageToVars.afinish = true;
					pageToVars.current.hide();
					pageToVars.current.off("webkitAnimationEnd", pageToVars.onevt);
					if (pageToVars.type === "scale" || pageToVars.type === "poker") {
						if (pageToVars.type === "poker") {
							pageToVars.current.parent().removeStyle("-" + vendor + "-perspective");
							pageToVars.current.parent().removeStyle("-" + vendor + "-transform-style");
							pageToVars.target.parent().style("-" + vendor + "-perspective", "2000px");
						}
						pageToVars.target.css("-" + vendor + "-animation", "pageAnimateRunTarget " + pageToVars.runTime + "s " + pageToVars.ease);
						pageToVars.target.show();
					} else if (pageToVars.bfinish) {
						pageToVars.end();
					}
				} else if (e.target == pageToVars.target[0]) {
					pageToVars.bfinish = true;
					pageToVars.target.off("webkitAnimationEnd", pageToVars.onevt);
					if (pageToVars.bfinish) {
						pageToVars.end();
					}
				}
			}
		},
		end: function() {
			if ($.pageToing) {
				$.pageToing = false;
	            
	            // 如果有高亮，去除
	            if (this.hover) {
	                this.hover.removeAttr("hover");
	            }
	            
				// 去除动画样式
				pageToVars.current.removeStyle("-" + vendor + "-animation").removeStyle("pointerEvents");
				pageToVars.target.removeStyle("-" + vendor + "-animation").removeStyle("pointerEvents");
				if (pageToVars.type === "poker") {
					pageToVars.current.parent().removeStyle("-" + vendor + "-perspective");
					pageToVars.target.parent().removeStyle("-" + vendor + "-perspective");
				}

				// 转出去的页隐藏，转进来的页显示
				this.current.hide();
				this.target.show();

				// 显示当前
				$("*[_c_='true']").removeAttr("_c_");
				this.target.attr("_c_", "true");

				// 如果有回调函数，回调
				if (this.callback) {
					setTimeout(this.callback, 0);
				}
			}
		}
	}


	// 侦听整个页面input的focus和blur事件，使其在转场的时候失去焦点
	var inputFocus = {
		init: function() {
			$("input").on("focus blur", this.inputEvents);
		},
		inputEvents: function(e) {
			if (e.type === "focus") {
				inputFocus.is = true;
				inputFocus.elem = this;
			} else {
				inputFocus.is = false;
				inputFocus.elem = null;
			}
		},
		is: false,
		elem: null
	}
	inputFocus.init();


	$.extend($.fn, {
		iScroll: function(c) {
			this.css({"overflow": "scroll", "overflow-x": "hidden"});
            if (isIOS) {
                this.css({"-webkit-overflow-scrolling": "touch"});
            }
            // 添加下拉刷新事件
            if (c) {
                if(c.onScrollMove) {
                    this.on("touchmove", c.onScrollMove);
                }
                if(c.onScrollEnd) {
                    this.on("touchend", c.onScrollEnd);
                }
                if(c.onRefresh) {
                    this.__proto__.iScroll.onRefresh = c.onRefresh;
                }
            }
			return this;
		},
		child: function(el) {
			return this.find(el);
		},
		show: function(c) {
			// 可设置为display: table等除block以外的值
			return this.css("display", c ? c : "block");
		},
		style: function(c, d) {
			// 同css()
			return this.css(c, d);
		},
		loadImg: function(c) {
			// 加载图片，格式为<img load="img_url.jpg" />
			var imgs = this,
			cb = function(e){
				this.style["visibility"] = "";
				this.style["opacity"] = "";
				if (this.getAttribute("style") == "") {
					this.removeAttribute("style");
				}
				this.removeAttribute("load");
				if (c && $.isFunction(c)) {
					c(this);
				} else if (typeof c === "number") {
					this.style["webkitTransition"] = "opacity " + c / 1000 + "s ease";
					this.style["opacity"] = 1;
				}
			};
			for (var i = 0, len = imgs.length; i < len; i++) {
				var m = imgs[i];
				if (m.getAttribute("load")) {
					m.style["visibility"] = "hidden";
					m.style["opacity"] = 0;
					m.src = m.getAttribute("load");
					m.addEventListener("load", cb);
				}
			}

			return this;
		},
		hover: function() {
			// var L = this;
			// for (var i = 0, len = L.length; i < len; i++) {
			// 	L[i].addEventListener("touchstart", touchHover.start, false);
			// 	L[i].addEventListener("touchmove", touchHover.move, false);
			// 	L[i].addEventListener("touchend", touchHover.end, false);
			// }
			this.on("touchstart", touchHover.start);
			this.on("touchmove", touchHover.move);
			this.on("touchend", touchHover.end);
			return this;
		},
		removeHover: function() {
			// var L = this;
			// for (var i = 0, len = L.length; i < len; i++) {
			// 	L[i].removeEventListener("touchstart", touchHover.start, false);
			// 	L[i].removeEventListener("touchmove", touchHover.move, false);
			// 	L[i].removeEventListener("touchend", touchHover.end, false);
			// }
			this.off("touchstart", touchHover.start);
			this.off("touchmove", touchHover.move);
			this.off("touchend", touchHover.end);
			return this;
		},
		pageTo: function(el, o) {
			// 如果在转场时有input的获焦状态，则取消
			if (inputFocus.is) {
				$(inputFocus.elem).blur();
				inputFocus.is = false;
				inputFocus.elem = null;
			}
			//新版写法 E.pageTo(E, { type: "move", callback: fn, hover: E});
			if( $.zepto.isZ(el) ) {
				if (o) {
					pageToVars.current = this;
					pageToVars.target = el;
					pageToVars.type = o.type || "none";
					pageToVars.callback = o.callback;
					pageToVars.hover = o.hover;
					pageToVars.back = o.back;
					pageToVars.start();
				} else {
					if (pageToVars.callback) {
						pageToVars.callback();
					}
					this.css("display", "none");
					return el.css("display", "block");
				}
			} else if (!o) {
				// 兼容旧版的写法
				// E.pageto({ target: E, type: "move", callback: fn, hover: E});
				o = el;
				if (o.target) {
					pageToVars.current = this;
					pageToVars.target = o.target;
					pageToVars.type = o.type;
					pageToVars.callback = o.callback;
					pageToVars.hover = o.hover;
					pageToVars.back = o.back;
					pageToVars.start();
				}
			}
		},
		pageto: function(el, o){
			// 兼容旧版的pageto全小写写法
			return this.pageTo(el, o);
		},
		innerHTML: function(e){
			// 兼容旧版的innerHTML方法
			return this.html(e);
		},
		removeCss: function(e) {
			if (e) {
				this.css(e, "");
				if (this.css(e) == null) {
					this.removeAttr("style");
				}
			} else {
				this.removeAttr("style");
			}
			return this;
		},
		removeStyle: function(e) {
			// 兼容removeCss
			return this.removeCss(e);
		},
		on: function (event, selector, callback) {
			// 对bind方法添加功能，如果在触摸屏下，click被转为touchend
			// 使用click!才能正常的支持click事件
			if (hasTouch && event === "click") {
				event = "touchend";
			}
			if (event === "click!") {
				event = "click";
			}
		    return selector == undefined || $.isFunction(selector) ?
		      	this.bind(event, selector) : this.delegate(selector, event, callback)
		},
		off: function (event, selector, callback){
			if (hasTouch && event === "click") {
				event = "touchend";
			}
			if (event === "click!") {
				event = "click";
			}
			return selector == undefined || $.isFunction(selector) ?
		  		this.unbind(event, selector) : this.undelegate(selector, event, callback)
		},
		scrollTop: function(n, s) {
			if (n !== null) {
				if (typeof n === "number" || (typeof n === "string" && (/^(\+|\-)(\d+|\d+\.\d+)$/).test(n))) {
					var _n = 0;
					if (typeof n === "number") {
						_n = n;
					} else {
						_n = this[0].scrollTop + parseInt(n);
					}
					if (s == null) {
						this[0].scrollTop = _n;
					} else {
						// 动画滚动
					}
				}
			} else {
				return this[0].scrollTop;
			}
		}
	});



	var nadoui = {
		init: function() {
			// 如果页面有id为nadoui的容器，先删除
			if($("#_nadoui_") != null) {
				$("#_nadoui_").remove();
			}
			var _uihtml = "<div id='_nadoui_'><div class='inner'>";
			_uihtml += "<div ui class='_nadoload_'><div class='loading' type='12'></div><span>加载中</span></div>";
			_uihtml += "<div ui class='_nadoerror_'><div class='error'></div><span>!<br />未知错误</span></div>";
			_uihtml += "</div></div>";
			$("body").append(_uihtml);
			nadoui.div = $("#_nadoui_");
			nadoui.div.on("touchmove", function(e){
				e.preventDefault();
			});
		},
		load: function(txt) {
			$("#_nadoui_ div[ui]").hide();
			$("#_nadoui_ ._nadoload_").show().find("span").html(txt);
		},
		error: function(txt) {
			$("#_nadoui_ div[ui]").hide();
			$("#_nadoui_ ._nadoerror_").show();
		},
		remove: function() {
			nadoui.div.css("display","none");
		},
		div: null,
		timeout: null
	};
	nadoui.init();


	$.extend($, {
		// 系统的相关信息
		system: {
			// 系统类型: ios android or windows
			type: function() {
				if (isAndroid) {
					return "android";
				} else if (isIOS) {
					return "ios";
				} else if (isWindows) {
					// windows 8 并没有实际验证过结果是否正确
					return "windows";
				}
			}
		},
		// 基础界面
		ui: {
			loading: function(t, txt) {
				if(t == "show" || t == null) {
					nadoui.load( txt? txt : "加载中" );
					nadoui.div.css({"display": "table", "background": "rgba(0,0,0,0)"});
					clearTimeout(nadoui.timeout);
					nadoui.timeout = setTimeout(function(){
						nadoui.div.css("display","none");
					}, 6000);
				} else {
					clearTimeout(nadoui.timeout);
					nadoui.remove();
				}
			},
			photo: function(url){
				nadoui.photo(url);
				nadoui.div.css({"display": "table", "background": "rgba(0,0,0,0.8)"});
			},
			error: function(txt){
				nadoui.error( txt? txt : "未知错误" );
				nadoui.div.css({"display": "table", "background": "rgba(0,0,0,0)"});
			}
		},
		bodyHeight: function(){
			return document.height || document.body.scrollHeight;
		},
		bodyWidth: function(){
			return document.width || document.body.scrollWidth;
		},
        focus: function(){
            return inputFocus.elem;
        },
		isIOS: function(){
			return isIOS;
		},
		pageAnimating: function(){
			return this.pageToing;
		},
		touchmoved: function(){
			return this.touchMoved;
		},
		isEmpty: function(value, allowEmptyString){
			return (value === null) || (value === undefined) || (!allowEmptyString ? value === '' : false) || (this.isArray(value) && value.length === 0);
		},
		isArray: ('isArray' in Array) ? Array.isArray : function(value) {
        	return toString.call(value) === '[object Array]';
    	},
    	from: function(value, newReference) {
	        if (value === undefined || value === null) {
	            return [];
	        }

	        if (this.isArray(value)) {
	            return (newReference) ? slice.call(value) : value;
	        }

	        if (value && value.length !== undefined && typeof value !== 'string') {
	            return this.toArray(value);
	        }

	        return [value];
	    },
	    toArray: function(iterable, start, end){
	        if (!iterable || !iterable.length) {
	            return [];
	        }

	        if (typeof iterable === 'string') {
	            iterable = iterable.split('');
	        }

	        if (supportsSliceOnNodeList) {
	            return slice.call(iterable, start || 0, end || iterable.length);
	        }

	        var array = [],
	            i;

	        start = start || 0;
	        end = end ? ((end < 0) ? iterable.length + end : end) : iterable.length;

	        for (i = start; i < end; i++) {
	            array.push(iterable[i]);
	        }

	        return array;
	    },
	    cfEach: function(array, fn, scope, reverse) {
	        array = this.from(array);

	        var i,
	            ln = array.length;

	        if (reverse !== true) {
	            for (i = 0; i < ln; i++) {
	                if (fn.call(scope || array[i], array[i], i, array) === false) {
	                    return i;
	                }
	            }
	        }
	        else {
	            for (i = ln - 1; i > -1; i--) {
	                if (fn.call(scope || array[i], array[i], i, array) === false) {
	                    return i;
	                }
	            }
	        }

	        return true;
	    },
		delay:function(delay, newFn, newScope, newArgs) {
			var me=this;
            me.updateInterval(null,oldInterval);
			//create the callback method for this delayed task
			var call = function() {
				newFn.apply(newScope,newArgs || []);
                me.updateInterval(null,oldInterval);
			};
			oldInterval=setInterval(call, delay);
		},
		updateInterval:function(newInterval, oldInterval) {
			if (oldInterval) {
				clearInterval(oldInterval);
			}
		},
        ////将带有长秒的时间字符串转成Date型 eg：2012-8-17 00:00:00
        longStrToDate:function(str){
            if(!this.isEmpty(str))
            {
                var aryDMY= new Array();
                aryDMY=str.split(' ');
                var arys= new Array();
                arys=aryDMY[0].split('-');
                var newDate=new Date(arys[0],arys[1]-1,arys[2]);
                return newDate;
            }
            else
            {
                return new Date();
            }
        },
        htmlDecode: (function() {
            var entities = {
                '&amp;': '&',
                '&gt;': '>',
                '&lt;': '<',
                '&quot;': '"'
            }, keys = [], p, regex;

            for (p in entities) {
                keys.push(p);
            }

            regex = new RegExp('(' + keys.join('|') + '|&#[0-9]{1,5};' + ')', 'g');

            return function(value) {
                return (!value) ? value : String(value).replace(regex, function(match, capture) {
                    if (capture in entities) {
                        return entities[capture];
                    } else {
                        return String.fromCharCode(parseInt(capture.substr(2), 10));
                    }
                });
            };
        })(),
		touchMoved: false,
		pageToing: false
	})


	window.$ = Zepto;
})(Zepto);